import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';

/// 签到弹窗
class SignDialog extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Material(
        type: MaterialType.transparency,
        child: Center(
          child: Container(
            width: 335.w,
            child: Stack(
              children: [
                Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Image.asset(
                      'assets/images/image_sign_bg.png',
                      width: 335.w,
                      height: 99.h,
                      fit: BoxFit.fill,
                    ),
                    Container(
                      decoration: BoxDecoration(
                        color: bgWhiteColor,
                        borderRadius: BorderRadius.circular(12.w)
                      ),
                      child: Column(
                        children: [
                          Container(
                            height: 66.w,
                            width: 335.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: bgSignHead,
                              borderRadius: BorderRadius.vertical(top: Radius.circular(12.w))
                            ),
                            child: Text(
                              '每日签到',
                              style: TextStyle(
                                color: textWhiteColor,
                                fontWeight: FontWeight.bold,
                                fontSize: 20.sp
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(top: 12.h),
                            child: Wrap(
                              spacing: 9.w,
                              runSpacing: 6.h,
                              children: commonPageController.signRecordArr.map((item) {
                                return Container(
                                  width: 44.w,
                                  height: 70.h,
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(5.w),
                                    color: getSignBgColor('${item.status}')
                                  ),
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                      Text(
                                        '${item.day}',
                                        style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 12.sp,
                                          color: getTitleTextColor('${item.status}')
                                        ),
                                      ),
                                      SizedBox(height: 3.h),
                                      Image.asset(
                                        getSignIcon('${item.status}'),
                                        width: 24.w,
                                        height: 24.w,
                                      ),
                                      SizedBox(height: 3.h),
                                      Text(
                                        '${item.score}',
                                        style: TextStyle(
                                          fontSize: 12.sp,
                                          color: getSubTitleTextColor('${item.status}')
                                        ),
                                      )
                                    ],
                                  ),
                                );
                              }).toList(),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 71.w, vertical: 20.h),
                            child: commonPageController.userData.value.isSignDaily! <=0 ? ButtonUtil(
                              text: '签到', 
                              fontSize: 14.sp, 
                              borderRadius: 36.h, 
                              height: 36.h, 
                              onTop: () async {
                                await commonPageController.userSign();
                              }
                            ) : ButtonUtil(
                              text: '签到', 
                              fontSize: 14.sp, 
                              borderRadius: 36.h, 
                              height: 36.h, 
                              textColor: textSubtitleColor,
                              bgColors: [
                                bgDisplayColor,
                                bgDisplayColor,
                              ],
                              onTop: () async {}
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                ),
                Positioned(
                  top: 51.h,
                  child: Container(
                    width: 335.w,
                    padding: EdgeInsets.symmetric(horizontal: 42.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Image.asset(
                          'assets/icons/icon_sign_icon.png',
                          width: 27.w,
                          height: 69.h,
                        ),
                        Image.asset(
                          'assets/icons/icon_sign_icon.png',
                          width: 27.w,
                          height: 69.h,
                        )
                      ],
                    ),
                  )
                ),
                Positioned(
                  top: 88.h,
                  right: 0,
                  child: InkWellUtil.shakeProofInkWell(Image.asset(
                    'assets/icons/icon_close_w.png',
                    width: 30.w,
                    height: 30.w,
                  ), () {
                    Get.back();
                  },
                  hoverColor: Colors.transparent,
                  splashColor: Colors.transparent,
                  highlightColor: Colors.transparent)
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  /// 获取签到背景颜色
  getSignBgColor(String status) {
    Map<String, dynamic> map = {
      '1': textColorIntegralAdd,
      '2': bgDisplayColor,
      '3': bgDisplayColor,
      '4': bgSignHead
    };
    return map['$status'];
  }

  /// 获取签到背景颜色
  getTitleTextColor(String status) {
    Map<String, dynamic> map = {
      '1': textWhiteColor,
      '2': textBlackColor,
      '3': textBlackColor,
      '4': textWhiteColor
    };
    return map['$status'];
  }
  
  /// 获取签到背景颜色
  getSubTitleTextColor(String status) {
    Map<String, dynamic> map = {
      '1': textWhiteColor,
      '2': textSubtitleColor,
      '3': textSubtitleColor,
      '4': textWhiteColor
    };
    return map['$status'];
  }
  
  /// 签到Icon
  getSignIcon(String status) {
    Map<String, dynamic> map = {
      '1': 'assets/icons/icon_sign_success.png',
      '2': 'assets/icons/icon_sign_error.png',
      '3': 'assets/icons/icon_sign_integral.png',
      '4': 'assets/icons/icon_sign_integral.png'
    };
    return map['$status'];
  }
}